package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.LeescoreGoods;
import com.kede.app.service.LeescoreGoodsService;
import com.kede.app.service.dto.LeescoreGoodsQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-05-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "goods管理")
@RequestMapping("/api/leescoreGoods")
public class LeescoreGoodsController {

    private final LeescoreGoodsService leescoreGoodsService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('leescoreGoods:list')")
    public void exportLeescoreGoods(HttpServletResponse response, LeescoreGoodsQueryCriteria criteria) throws IOException {
        leescoreGoodsService.download(leescoreGoodsService.queryAll(criteria), response);
    }

    /**
    * 查询goods
    **/
    @GetMapping
    @ApiOperation("查询goods")
    @PreAuthorize("@el.check('leescoreGoods:list')")
    public ResponseEntity<Object> queryLeescoreGoods(LeescoreGoodsQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(leescoreGoodsService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增goods
    **/
    @PostMapping
    @Log("新增goods")
    @ApiOperation("新增goods")
    @PreAuthorize("@el.check('leescoreGoods:add')")
    public ResponseEntity<Object> createLeescoreGoods(@Validated @RequestBody LeescoreGoods resources){
        return new ResponseEntity<>(leescoreGoodsService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改goods
    **/
    @PutMapping
    @Log("修改goods")
    @ApiOperation("修改goods")
    @PreAuthorize("@el.check('leescoreGoods:edit')")
    public ResponseEntity<Object> updateLeescoreGoods(@Validated @RequestBody LeescoreGoods resources){
        leescoreGoodsService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除goods
    **/
    @DeleteMapping
    @Log("删除goods")
    @ApiOperation("删除goods")
    @PreAuthorize("@el.check('leescoreGoods:del')")
    public ResponseEntity<Object> deleteLeescoreGoods(@RequestBody Integer[] ids) {
        leescoreGoodsService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}